import myaxios from '../../utils/myAixos'
import "./edit.css"
import {  useLocation } from "react-router-dom";
import { Button, Form, Input, Radio,Select} from 'antd';
import { LeftOutlined } from '@ant-design/icons';
import { useEffect } from "react";
import { data } from 'browserslist';
const Edit = () => {

  //获取页面传参的值，并放入输入框中
  const [form] = Form.useForm();
  const { setFieldsValue } = form;
  let location = useLocation();
  console.log(location.state)
  useEffect(() => {
    if (location.state.v_status === '正常') {
      location.state.v_status = true
    } else {
      location.state.v_status = false
    }
    setFieldsValue(location.state)
  }, [])

  //返回上一页
  const back = () => {
    window.history.back(-1)
  }
  // const { TextArea } = Input;

  //提交表单
  
  const onFinish = (values) => {
    console.log(location.state.v_id)
    
    console.log('Finish:', values);
    // let myForData = new FormData()
    myaxios({
      url: '/venueEdit',
      method:'post',
      data:{
        v_address:values.v_address,
        v_name:values.v_name,
        v_phone:values.v_phone,
        v_email:values.v_email,
        v_status:values.v_status,
        v_classname:values.v_classname,
        v_number:values.v_number,
        v_teacher:values.v_teacher,
        v_time:values.v_time,
        v_id:location.state.v_id
      }
    }).then(res=>{
      console.log('编辑结果',res)
      if(res.status === 200){
        console.log('编辑成功')
        window.history.back(-1)
      }else{
        console.log('编辑错误')
      }
    }).catch(err =>{
      console.log('编辑错误')
    })
  }
  // const options = [
  //   {
  //     value: '福州',
  //     label: '福州',
     
  //   },
  //   {
  //     value: '江苏',
  //     label: '江苏',
  //     children: [
  //       {
  //         value: '南京',
  //         label: '南京',
  //         children: [
  //           {
  //             value: '中华门',
  //             label: '中华门',
  //           },
  //         ],
  //       },
  //     ],
  //   },
  // ];
  return (
    <div className="body1">
      <div className="header1">
        <span>场馆编辑</span>
        <span className="btn" onClick={back}>
          {/* <Space> */}
            <LeftOutlined />
          {/* </Space> */}
          返回</span>
      </div>
      <div className="body11">
        <Form
          form={form}
          name="basic"
          labelCol={{ span: 8 }}
          wrapperCol={{ span: 16 }}
          onFinish={onFinish}
          style={{ maxWidth: 600 }}
          initialValues={{ remember: true }}
          autoComplete="off"
        >
           <Form.Item
            label="场馆名称"
            name="v_name"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Input placeholder="符号健身馆" />
          </Form.Item>
          

          <Form.Item
            label="电话"
            name="v_phone"
            rules={[{ required: true, message: '请输入内容' }]}
          >
            <Input placeholder="13333333333" />
          </Form.Item>
          <Form.Item className="dv"
            label="地址"
            name="v_address"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Select style={{width:'200px'}}>
              <option value="福州">福州</option>
              <option value="江苏">江苏</option>
              <option value="北京">北京</option>

            </Select>
          </Form.Item>
          <Form.Item 
            label="课程类型"
            name="v_classname"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Select style={{width:'400px'}}>
              <option value="极速减脂">极速减脂</option>
              <option value="瑜伽教学">瑜伽教学</option>
              <option value="举重练习">举重练习</option>
              <option value="卧推训练">卧推训练</option>
            </Select>
          </Form.Item>
          <Form.Item
            label="最大人数"
            name="v_number"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Input placeholder="100" />
          </Form.Item>
          <Form.Item
            label="任课教练"
            name="v_teacher"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Input placeholder="" />
          </Form.Item>
          <Form.Item  className="dv"
            label="任课时段"
            name="v_time"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Select style={{width:'200px'}}>
            <option value="19:00 - 19:45">19:00 - 19:40</option>
              <option value="20:00 - 20:40">20:00 - 20:40</option>
              <option value="21: - 21:40">21: - 21:40</option>
            </Select>
          </Form.Item>
          <Form.Item
            label="邮箱"
            name="v_email"
            rules={[{ required: true, message: '请输入内容!' }]}
          >
            <Input placeholder="123@123.com" />
          </Form.Item>
          <Form.Item
            label="状态"
            name="v_status"
            rules={[{ required: true, message: '状态不能为空' }]}
          >
            <Radio.Group name="radiogroup" defaultValue={1} style={{ display: "flex", }}>
              <Radio value={true}>启用</Radio>
              <Radio value={false}>禁用</Radio>
            </Radio.Group>
          </Form.Item>
          {/* <Form.Item
            label="介绍"
            
          >
            <>
              <TextArea rows={4} placeholder="场馆介绍" maxLength={6} />
            </>
          </Form.Item> */}

          {/* <Form.Item
            label="是否默认场馆"
            name="是否默认场馆"
            rules={[{ required: true, message: 'Please input your password!' }]}
          >
            <Radio.Group name="radiogroup" defaultValue={1} style={{ display: "flex", }}>
              <Radio value={1}>是</Radio>
              <Radio value={2}>否</Radio>
            </Radio.Group>
          </Form.Item> */}


          {/* <Form.Item name="remember" valuePropName="checked" wrapperCol={{ offset: 8, span: 16 }}>
            <Checkbox>Remember me</Checkbox>
          </Form.Item> */}

          <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
            <Button type="primary" htmlType="submit" >
              提交
            </Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  );
};
export default Edit;
